<?php
/**
 * 客服设置
 */

namespace App\backend\controllers\setting;

use App\backend\services\SettingCustomerServiceServices;
use App\backend\controllers\AdminBaseController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class CustomerServiceController extends AdminBaseController
{

    /**
     * 列表
     */
    public function getList(Request $request)
    {
        $result = SettingCustomerServiceServices::getPageList($request);

        return successJson('ok', $result);

    }

    /**
     * 添加/编辑
     */
    public function setModify(Request $request)
    {
        $data = $request->all();
        $validator = Validator::make($data,
            [
                'wechatNum' => 'required|string|max:50',
            ],
            [
                'wechatNum.required' => '微信号不能为空',
                'wechatNum.max' => '微信号长度超过最大限制'
            ]);

        if ($validator->fails()){
            return errorJson($validator->errors()->first());
        }

        $result = SettingCustomerServiceServices::modify($data);
        if ($result) {
            return successJson('操作成功');
        }
        return errorJson('操作失败');
    }

    /**
     * 删除
     */
    public function optDelete(Request $request)
    {
        $data = $request->all();
        $validator = Validator::make($data,
            [
                'id' => 'required',
            ],
            [
                'id.required' => '幻灯片ID不能为空'
            ]);

        if ($validator->fails()){
            return errorJson($validator->errors()->first());
        }

        $result = SettingCustomerServiceServices::delete($data);
        if ($result) {
            return successJson('操作成功');
        }
        return errorJson('操作失败');

    }

}
